//
//  WallHitEffect.m
//  BeatPong
//
//  Created by Gabriel Lumbi on 12-09-22.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "WallHitEffect.h"

@implementation WallHitEffect

@synthesize xDisplacement;

#pragma mark -
#pragma mark Life Cycle

-(id) init
{
    if(self = [super init])
    {
        maxLength = 50.f;
        lifespan = 0.3f;
        xDisplacement = 50.f;
    }
    return self;
}

#pragma mark -
#pragma mark Draw

-(void) draw
{
    [super draw];
    
    if(!self.over){
        float percent = (log1pf(currentTime/lifespan*100))/ (log1pf(lifespan*100)+2);
        float length = maxLength * percent;
        ccDrawColor4F(1, 0, 1, 1);
        
        CGPoint top = ccp(self.position.x + percent * xDisplacement,
                          self.position.y + length / 2.f);
        CGPoint bottom = ccp(self.position.x + percent * xDisplacement,
                             self.position.y - length / 2.f);
        
        ccDrawLine([self convertToNodeSpace: top],
                   [self convertToNodeSpace: bottom]);
    }
}

@end
